home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevmem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  10.0 KB  |  244 lines

  1. /* Copyright (C) 1991, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevmem.h,v 1.3 2000/09/19 19:00:14 lpd Exp $ */
  20. /* Private definitions for memory devices. */
  21.  
  22. #ifndef gdevmem_INCLUDED
  23. #  define gdevmem_INCLUDED
  24.  
  25. #include "gxbitops.h"
  26.  
  27. /*
  28.    The representation for a "memory" device is simply a
  29.    contiguous bitmap stored in something like the PostScript
  30.    representation, i.e., each scan line (in left-to-right order), padded
  31.    to a multiple of bitmap_align_mod bytes, followed immediately by
  32.    the next one.
  33.  
  34.    The representation of strings in the interpreter limits
  35.    the size of a string to 64K-1 bytes, which means we can't simply use
  36.    a string for the contents of a memory device.
  37.    We get around this problem by making the client read out the
  38.    contents of a memory device bitmap in pieces.
  39.  
  40.    On 80x86 PCs running in 16-bit mode, there may be no way to
  41.    obtain a contiguous block of storage larger than 64K bytes,
  42.    which typically isn't big enough for a full-screen bitmap.
  43.    We take the following compromise position: if the PC is running in
  44.    native mode (pseudo-segmenting), we limit the bitmap to 64K;
  45.    if the PC is running in protected mode (e.g., under MS Windows),
  46.    we assume that blocks larger than 64K have sequential segment numbers,
  47.    and that the client arranges things so that an individual scan line,
  48.    the scan line pointer table, and any single call on a drawing routine
  49.    do not cross a segment boundary.
  50.  
  51.    Even though the scan lines are stored contiguously, we store a table
  52.    of their base addresses, because indexing into it is faster than
  53.    the multiplication that would otherwise be needed.
  54.  */
  55.  
  56. /*
  57.  * Macros for scan line access.
  58.  * x_to_byte is different for each number of bits per pixel.
  59.  * Note that these macros depend on the definition of chunk:
  60.  * each procedure that uses the scanning macros should #define
  61.  * (not typedef) chunk as either uint or byte.
  62.  */
  63. #define declare_scan_ptr(ptr)\
  64.     DECLARE_SCAN_PTR_VARS(ptr, chunk *, draster)
  65. #define DECLARE_SCAN_PTR_VARS(ptr, ptype, draster)\
  66.     register ptype ptr;\
  67.     uint draster
  68. #define setup_rect(ptr)\
  69.     SETUP_RECT_VARS(ptr, chunk *, draster)
  70. #define SETUP_RECT_VARS(ptr, ptype, draster)\
  71.     draster = mdev->raster;\
  72.     ptr = (ptype)(scan_line_base(mdev, y) +\
  73.       (x_to_byte(x) & -chunk_align_bytes))
  74.  
  75. /* ------ Generic macros ------ */
  76.  
  77. /* Macro for declaring the essential device procedures. */
  78. dev_proc_get_initial_matrix(mem_get_initial_matrix);
  79. dev_proc_close_device(mem_close);
  80. #define declare_mem_map_procs(map_rgb_color, map_color_rgb)\
  81.   private dev_proc_map_rgb_color(map_rgb_color);\
  82.   private dev_proc_map_color_rgb(map_color_rgb)
  83. #define declare_mem_procs(copy_mono, copy_color, fill_rectangle)\
  84.   private dev_proc_copy_mono(copy_mono);\
  85.   private dev_proc_copy_color(copy_color);\
  86.   private dev_proc_fill_rectangle(fill_rectangle)
  87. /*
  88.  * We define one relatively low-usage drawing procedure that is common to
  89.  * all memory devices so that we have a reliable way to implement
  90.  * gs_is_memory_device.  It is equivalent to gx_default_draw_thin_line.
  91.  */
  92. dev_proc_draw_thin_line(mem_draw_thin_line);
  93.  
  94. /* The following are used for all except planar or word-oriented devices. */
  95. dev_proc_open_device(mem_open);
  96. dev_proc_get_bits_rectangle(mem_get_bits_rectangle);
  97. /* The following are for word-oriented devices. */
  98. #if arch_is_big_endian
  99. #  define mem_word_get_bits_rectangle mem_get_bits_rectangle
  100. #else
  101. dev_proc_get_bits_rectangle(mem_word_get_bits_rectangle);
  102. #endif
  103. /* The following are used for the non-true-color devices. */
  104. dev_proc_map_rgb_color(mem_mapped_map_rgb_color);
  105. dev_proc_map_color_rgb(mem_mapped_map_color_rgb);
  106. /* Default implementation */
  107. dev_proc_strip_copy_rop(mem_default_strip_copy_rop);
  108.  
  109. /*
  110.  * Macro for generating the device descriptor.
  111.  * Various compilers have problems with the obvious definition
  112.  * for max_value, namely:
  113.  *      (depth >= 8 ? 255 : (1 << depth) - 1)
  114.  * I tried changing (1 << depth) to (1 << (depth & 15)) to forestall bogus
  115.  * error messages about invalid shift counts, but the H-P compiler chokes
  116.  * on this.  Since the only values of depth we ever plan to support are
  117.  * powers of 2 (and 24), we just go ahead and enumerate them.
  118.  */
  119. #define max_value_gray(rgb_depth, gray_depth)\
  120.   (gray_depth ? (1 << gray_depth) - 1 : max_value_rgb(rgb_depth, 0))
  121. #define max_value_rgb(rgb_depth, gray_depth)\
  122.   (rgb_depth >= 8 ? 255 : rgb_depth == 4 ? 15 : rgb_depth == 2 ? 3 :\
  123.    rgb_depth == 1 ? 1 : (1 << gray_depth) - 1)
  124. #define mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, map_cmyk_color, copy_alpha, strip_tile_rectangle, strip_copy_rop, get_bits_rectangle)\
  125. {    std_device_dci_body(gx_device_memory, 0, name,\
  126.       0, 0, 72, 72,\
  127.       (rgb_depth ? 3 : 0) + (gray_depth ? 1 : 0),    /* num_components */\
  128.       rgb_depth + gray_depth,    /* depth */\
  129.       max_value_gray(rgb_depth, gray_depth),    /* max_gray */\
  130.       max_value_rgb(rgb_depth, gray_depth),    /* max_color */\
  131.       max_value_gray(rgb_depth, gray_depth) + 1, /* dither_grays */\
  132.       max_value_rgb(rgb_depth, gray_depth) + 1 /* dither_colors */\
  133.     ),\
  134.     {    open,            /* differs */\
  135.         mem_get_initial_matrix,\
  136.         gx_default_sync_output,\
  137.         gx_default_output_page,\
  138.         mem_close,\
  139.         map_rgb_color,        /* differs */\
  140.         map_color_rgb,        /* differs */\
  141.         fill_rectangle,        /* differs */\
  142.         gx_default_tile_rectangle,\
  143.         copy_mono,        /* differs */\
  144.         copy_color,        /* differs */\
  145.         gx_default_draw_line,\
  146.         gx_default_get_bits,\
  147.         gx_default_get_params,\
  148.         gx_default_put_params,\
  149.         map_cmyk_color,        /* differs */\
  150.         gx_forward_get_xfont_procs,\
  151.         gx_forward_get_xfont_device,\
  152.         gx_default_map_rgb_alpha_color,\
  153.         gx_forward_get_page_device,\
  154.         gx_default_get_alpha_bits,    /* default is no alpha */\
  155.         copy_alpha,        /* differs */\
  156.         gx_default_get_band,\
  157.         gx_default_copy_rop,\
  158.         gx_default_fill_path,\
  159.         gx_default_stroke_path,\
  160.         gx_default_fill_mask,\
  161.         gx_default_fill_trapezoid,\
  162.         gx_default_fill_parallelogram,\
  163.         gx_default_fill_triangle,\
  164.         mem_draw_thin_line,    /* see above */\
  165.         gx_default_begin_image,\
  166.         gx_default_image_data,\
  167.         gx_default_end_image,\
  168.         strip_tile_rectangle,    /* differs */\
  169.         strip_copy_rop,        /* differs */\
  170.         gx_default_get_clipping_box,\
  171.         gx_default_begin_typed_image,\
  172.         get_bits_rectangle,    /* differs */\
  173.         gx_default_map_color_rgb_alpha,\
  174.         gx_default_create_compositor,\
  175.         gx_default_get_hardware_params,\
  176.         gx_default_text_begin,\
  177.         gx_default_finish_copydevice\
  178.     },\
  179.     0,            /* target */\
  180.     mem_device_init_private    /* see gxdevmem.h */\
  181. }
  182. #define mem_full_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, map_cmyk_color, strip_tile_rectangle, strip_copy_rop, get_bits_rectangle)\
  183.   mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color,\
  184.             map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  185.             map_cmyk_color, gx_default_copy_alpha,\
  186.             strip_tile_rectangle, strip_copy_rop,\
  187.             get_bits_rectangle)
  188. #define mem_device(name, rgb_depth, gray_depth, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, strip_copy_rop)\
  189.   mem_full_device(name, rgb_depth, gray_depth, mem_open, map_rgb_color,\
  190.           map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  191.           gx_default_map_cmyk_color, gx_default_strip_tile_rectangle,\
  192.           strip_copy_rop, mem_get_bits_rectangle)
  193.  
  194. /* Swap a rectangle of bytes, for converting between word- and */
  195. /* byte-oriented representation. */
  196. void mem_swap_byte_rect(P6(byte *, uint, int, int, int, bool));
  197.  
  198. /* Copy a rectangle of bytes from a source to a destination. */
  199. #define mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h)\
  200.   bytes_copy_rectangle(scan_line_base(mdev, y) + x_to_byte(x),\
  201.                (mdev)->raster,\
  202.                base + x_to_byte(sourcex), sraster,\
  203.                x_to_byte(w), h)
  204.  
  205. /* ------ Implementations ------ */
  206.  
  207. extern const gx_device_memory mem_mono_device;
  208. extern const gx_device_memory mem_mapped2_device;
  209. extern const gx_device_memory mem_mapped4_device;
  210. extern const gx_device_memory mem_mapped8_device;
  211. extern const gx_device_memory mem_true16_device;
  212. extern const gx_device_memory mem_true24_device;
  213. extern const gx_device_memory mem_true32_device;
  214. extern const gx_device_memory mem_planar_device;
  215. /*
  216.  * We declare the RasterOp implementation procedures here because they are
  217.  * referenced in several implementation modules.
  218.  */
  219. dev_proc_strip_copy_rop(mem_mono_strip_copy_rop);
  220. dev_proc_strip_copy_rop(mem_gray_strip_copy_rop);
  221. dev_proc_strip_copy_rop(mem_gray8_rgb24_strip_copy_rop);
  222.  
  223. #if arch_is_big_endian
  224. #  define mem_mono_word_device mem_mono_device
  225. #  define mem_mapped2_word_device mem_mapped2_device
  226. #  define mem_mapped4_word_device mem_mapped4_device
  227. #  define mem_mapped8_word_device mem_mapped8_device
  228. #  define mem_true24_word_device mem_true24_device
  229. #  define mem_true32_word_device mem_true32_device
  230. #else
  231. extern const gx_device_memory mem_mono_word_device;
  232. extern const gx_device_memory mem_mapped2_word_device;
  233. extern const gx_device_memory mem_mapped4_word_device;
  234. extern const gx_device_memory mem_mapped8_word_device;
  235. extern const gx_device_memory mem_true24_word_device;
  236. extern const gx_device_memory mem_true32_word_device;
  237.  
  238. #endif
  239. /* Provide standard palettes for 1-bit devices. */
  240. extern const gs_const_string mem_mono_b_w_palette;    /* black=1, white=0 */
  241. extern const gs_const_string mem_mono_w_b_palette;    /* black=0, white=1 */
  242.  
  243. #endif /* gdevmem_INCLUDED */
  244.